# from multiprocessing import Process
# from multiprocessing import Queue
# import json
# import time
# import os
# import random
#
#
# def search(count):
#     time.sleep(random.randint(1,3))  # 模拟网络延迟(查询环节)
#     print(f'{os.getpid()} 查看了票数,剩余{count}')
#
#
# def paid(q):
#
#     dic = q.get()
#     if dic['count'] > 0:
#         dic['count'] -= 1
#         time.sleep(random.randint(1,3))  # 模拟网络延迟(购买环节)
#         print(f'{os.getpid()} 购买成功')
#     else:
#         print(f'{os.getpid()} 没票了')
#     q.put(dic)
#
#
# def task(q,count):
#     search(count)
#     paid(q)
#
#
# if __name__ == '__main__':
#     count= 3
#     q = Queue()
#     q.put({'count': count})
#     for i in range(10):
#         p = Process(target=task,args=(q,count))
#         p.start()
#




# 排队小米手机

from multiprocessing import Process
from multiprocessing import Queue
import os

def task(q):
    try:
        q.put(os.getpid(),block=False)
    except Exception:
        return

if __name__ == '__main__':
    q = Queue(10)

    for i in range(30):
        p = Process(target=task,args=(q,))
        p.start()

    for i in range(1,11):
        print(f'排名第{i}位的用户: {q.get()}')


















